package com.itheima.sc.web.pms;

import com.itheima.sc.pojo.pms.Brand;
import com.itheima.sc.pojo.pms.ProductAttribute;
import com.itheima.sc.pojo.pms.ProductAttributeCategory;
import com.itheima.sc.pojo.pms.ProductCategory;
import com.itheima.sc.result.Result;
import com.itheima.sc.service.pms.ProductCategoryService;
import com.itheima.sc.vo.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("productCategory")
public class ProductCategoryController {
    @Autowired
    private ProductCategoryService categoryService;

    //添加商品分类
    @PostMapping("create")
    public Result create(@RequestBody ProductCategory category){
        categoryService.create(category);
        return Result.success(null);
    }

    //删除商品分类
    @PostMapping("delete/{id}")  //删除单个品牌
    public Result delete(@PathVariable Integer id){
        categoryService.deleteById(id);
        return Result.success(null);
    }

    //查询所有一级分类及子分类
    @GetMapping("list/withChildren")
    public Result listWithChildren(){
        List<ProductCategory> categoryList = categoryService.listWithChildren();
        return Result.success(categoryList);
    }

    //根据parentId分页查询商品分类
    @GetMapping ("list/{parentId}")
    public Result listByParentId(@PathVariable Integer parentId,
                        @RequestParam(value = "pageNum",defaultValue = "1") Integer pageNum,
                        @RequestParam(value = "pageSize",defaultValue = "10")Integer pageSize){
        PageResult pageResult = categoryService.listByParentId(parentId,pageNum,pageSize);
        return Result.success(pageResult);
    }

    //修改导航栏显示状态
    @PostMapping("/update/navStatus")
    public Result updateNavStatus(@RequestParam Integer navStatus,
                                  @RequestParam List<Integer> ids){
        categoryService.updateNavStatus(navStatus,ids);
        return Result.success(null);
    }
    //修改显示状态
    @PostMapping("/update/showStatus")
    public Result updateShowStatus(@RequestParam Integer showStatus,
                                   @RequestParam List<Integer> ids){
        categoryService.updateShowStatus(showStatus,ids);
        return Result.success(null);
    }

    //修改商品分类
    @PostMapping("update/{id}")
    public Result updateById(@PathVariable Integer id,
                             @RequestBody ProductCategory category){
        categoryService.updateById(id,category);
        return Result.success(null);
    }

    //根据id获取商品分类
    @GetMapping("{id}")  //获取单个商品属性分类信息
    public Result getById(@PathVariable Integer id){
        ProductCategory category = categoryService.getById(id);
        return Result.success(category);
    }


















}
